import {cloneDeep,merge} from "lodash"
import {USER_INFO, LOGIN_OUT, CHANGE_PWD} from "../actions"

const initialState = {
  userInfo: sessionStorage.getItem("userInfo") ? JSON.parse(sessionStorage.getItem("userInfo")) : false
}

const handlers = {
  [USER_INFO]: (state, data) => {
    sessionStorage.setItem("userInfo", JSON.stringify(data))
    return merge()
  }
}

export default (state = initialState, action) => {
  const {type, data} = action
  if (!handlers[type]) {return state}
  return handlers[type](state, data)
}
